package com.example.helloandroid;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Result extends Activity {
	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onActivityResult(int, int,
	 * android.content.Intent)
	 */
	private  int max_table = 12;
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		textViewResulats.setText(Messages.getString("text.0") + data.getAction()+ Messages.getString("text.1")); //$NON-NLS-1$ //$NON-NLS-2$

	}

	private Button button1;
	private TextView textViewResulats;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.result);
		button1 = (Button) findViewById(R.id.Button01);
		button1.setOnClickListener(mButton1OnClickListener);
		textViewResulats = (TextView) findViewById(R.id.TextView01);
		textViewResulats.setText(""); //$NON-NLS-1$
	}
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu, menu);
		return true;
	};
	   protected Dialog onCreateDialog(int id, Bundle savedInstance ) {
	        switch (id) {
	        case (R.id.table) :
	        LayoutInflater factory = LayoutInflater.from(this);
            final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);
            return new AlertDialog.Builder(Result.this)
                .setTitle(R.string.alert_dialog_text_entry)
                .setView(textEntryView)
                .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    	
                    	EditText textTable = (EditText) textEntryView.findViewById(R.id.table_edit); 
                    	max_table = Integer.parseInt(textTable.getText().toString());
                
                    }
                })
                .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked cancel so do some stuff */
                    }
                })
                .create();
	        }
	        return null;
	   }
	public boolean onOptionsItemSelected(MenuItem item){
		switch (item.getItemId()) {
		case (R.id.table) :
			 // This example shows how to add a custom layout to an AlertDialog
			showDialog(R.id.table);
			return true;
		case(R.id.time) :
			return true;
		}
		return true;
	
		
	}
	
	private OnClickListener mButton1OnClickListener = new OnClickListener() {

		public void onClick(View v) {

			Intent intent = new Intent();
			intent.putExtra("MAX_TABLE", max_table); //$NON-NLS-1$
			intent.setClass(Result.this, HelloAndroid.class);
			startActivityForResult(intent, 0);

		};
		

	};
}
